class Solution {
public:
    double myPow(double x, int n) 
    {
        if(n == 0)
            return 1;

        double tmp = myPow(x, n / 2);
        if(n < 0) x = 1.0 / x;

        return n % 2 == 0 ? tmp * tmp : tmp * tmp * x;
    }
};